import { Client } from "@langchain/langgraph-sdk";


class langC{

    client = new Client({apiUrl:`${window.location.origin}/langC/`});  //AssistantsClient
    // 跑线程
    runsStream(threadId,agentId,data){
      // if(data.input.messages[0].content.indexOf("并且以中文回复，回复内容中不包含附件参考信息")==-1){
      //   data.input.messages[0].content = data.input.messages[0].content + "并且以中文回复，回复内容中不包含附件参考信息";
      // }
      return this.client.runs.stream(threadId,agentId,data);
    }
    // 助手操作
    async agentList(q){
      try{
        return await this.client.assistants.search(q);
      }catch(e){
        return false;
      }
    }
    async agentGet(id){ return await this.client.assistants.get(id);}
    async agentCreate(data){return !data? false: await this.client.assistants.create(data);}
    async agentUpdate(id,data){ return !data? false: await this.client.assistants.update(id,data);}
    async agentDelete(id){ return await this.client.assistants.delete(id);}
    async agentGetSchemas(id){ return await this.client.assistants.getSchemas(id);}

    // 线程操作
    async threadList(q) { return await this.client.threads.search(q);}
    async threadGet(id) { return await this.client.threads.get(id);}
    async threadCreate(data){return !data? false: await this.client.threads.create(data);}
    async threadUpdate(id,data) { return await this.client.threads.update(id,data);}
    async threadDelete(id) { return await this.client.threads.delete(id);}

    // 根据向量库名称删除向量库
    async delLangC(name){
      return fetch('/delLangC/v2/vectordb/collections/drop', {
        headers: {'accept': 'application/json','Content-Type':'application/json'},
        method: 'post',body:JSON.stringify({"collectionName": name}),
      })
    }
}
export default new langC();